/* poporctx.p - PURCHASE ORDER RECEIPTS SET TAX ENVIRONMENT IF SITE CHANGED   */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporctx.p 64242 2015-12-28 03:26:34Z kbh                         $: */
/*                                                                            */
/*                                                                            */
/* REVISION: 7.4      LAST MODIFIED: 07/02/93   BY: JJS *H020*                */
/*                                   03/22/94   BY: bcm *H299*                */
/*                                   02/23/95   BY: jzw *H0BM*                */
/* REVISION: 8.5      LAST MODIFIED: 01/07/98   By: *J29D* Jim Josey          */
/* REVISION: 9.0      LAST MODIFIED: 04/16/99   By: *J2DG* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane     */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.14 $   BY: Jack Rief      DATE: 06/13/00 ECO: *N0DK*          */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00 BY: *N0KQ* myb                  */
/* Revision: 1.13   BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00J* */
/* $Revision: 1.14 $    BY: Dan Herman      DATE: 11/04/04 ECO: *M1V1*        */
/*-Revision end---------------------------------------------------------------*/
 
 
{us/bbi/mfdeclre.i}
{us/px/pxmaint.i}
{us/bbi/gplabel.i} /* EXTERNAL LABEL INCLUDE */
 
define input        parameter po_recno        as   recid           no-undo.
define input        parameter site            like pod_site        no-undo.
define input        parameter podsite         like pod_site        no-undo.
define input        parameter taxable         like pod_taxable     no-undo.
define input        parameter taxc            like pod_taxc        no-undo.
define input-output parameter tax_usage       like pod_tax_usage   no-undo.
define input-output parameter tax_env         like pod_tax_env     no-undo.
define input-output parameter tax_in          like pod_tax_in      no-undo.
define input-output parameter undo-taxes      like mfc_logical     no-undo.
 
define variable zone_to   like txz_tax_zone no-undo.
define variable zone_from like txz_tax_zone no-undo.
 
{us/mf/mfaimfg.i}  /* Common API constants and variables */
 
{us/po/popoit01.i} /* Define API purchase order temp tables  */
{us/mf/mfctit01.i} /* Define API transaction comments temp tables */
 
if c-application-mode = "API" then do:
 
   /* Get handle of API controller */
   {us/bbi/gprun.i ""gpaigh.p"" "(output ApiMethodHandle,
                           output ApiProgramName,
                           output ApiMethodName,
                           output ApiContextString)"}
 
   /* Get current purchase order transaction detail record */
   run getPurchaseOrderTransDetRecord in ApiMethodHandle
      (buffer ttPurchaseOrderTransDet).
 
end. /* IF c-application-mode = "API" */
 
/* TAX ENVIRONMENT FORM */
form
   tax_usage     colon 25
   tax_env       colon 25
   tax_in        colon 25
with frame set_tax row 13 overlay centered side-labels.
 
/* SET EXTERNAL LABELS */
setFrameLabels(frame set_tax:handle).
 
for first po_mstr
   where recid(po_mstr) = po_recno no-lock:
end. /* FOR FIRST PO_MSTR */
 
/* GET TAX MANAGEMENT DATA ONLY IF THE SITE HAS BEEN CHANGED */
if site <> podsite then do:
   /* NEW SITE SPECIFIED; CHECK TAX ENVIRONMENT */
   {us/bbi/mfmsg.i 955 2}
   tax_env = "".
end. /* IF SITE <> PODSITE */
 
taxloop:
do on error undo, retry:
   /* SUGGEST TAX ENVIRONMENT */
   if tax_env = "" then do:
 
      /* GET TAX ZONES FROM SITE AND PO_SHIP ADDRESS */
      {us/px/pxrun.i &PROC = 'getTaxZones' &PROGRAM = 'porcxr.p'
               &PARAM = "(input site,
                          input po_vend,
                          output zone_to,
                          output zone_from)"
               &CATCHERROR = true
               &NOAPPERROR = true
      }
 
      /* SUGGEST A TAX ENVIRONMENT */
      {us/px/pxrun.i &PROC = 'getTaxEnvironment' &PROGRAM = 'txenvxr.p'
               &PARAM = "(input zone_to,
                          input zone_from,
                          input taxc,
                          output tax_env)"
               &CATCHERROR = true
               &NOAPPERROR = true
      }
   end. /* IF TAX_ENV = "" */
 
   if c-application-mode <> "API" then
      update
         tax_usage
         tax_env
         tax_in
      with frame set_tax.
 
   if c-application-mode = "API" then
      assign {us/mf/mfaiset.i tax_usage ttPurchaseOrderTransDet.taxUsage}
             {us/mf/mfaiset.i tax_env   ttPurchaseOrderTransDet.taxEnv}
             {us/mf/mfaiset.i tax_in    ttPurchaseOrderTransDet.taxIn}.
 
   {us/px/pxrun.i &PROC = 'validateTaxEnvironment' &PROGRAM = 'txenvxr.p'
            &PARAM="(input tax_env)"
            &CATCHERROR = true
            &NOAPPERROR = true
   }
   if return-value = {&APP-ERROR-RESULT} then do:
      next-prompt tax_env with frame set_tax.
      undo taxloop, retry.
   end.
 
   if c-application-mode <> "API" then
      hide frame set_tax.
   undo-taxes = false.
end. /* taxloop: */
